package com.bulk.url;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则匹配url
 *
 * @author 散装java
 * @date 2023-01-10
 */
public class UrlRegex {
    public static void main(String[] args) {
        String text = "http://www.baidu.com\n" +
                "ssss.zzz.acb.www.baidu.com.cn?abc=123\n" +
                "https://eqe9p3.yuque.com/rfgt6w/pyfagl/oh9x2ahwetavausu\n" +
                "https://www.baidu.com/s?ie=UTF-8&wd=%E8%AF%AD%E9%9B%80\n" +
                "xxx.xxx.xxx.xxx\n" +
                "xxx.com\n" +
                "http://121.43.34.55:8080/bops/index.html\n" +
                "xx.sr\n" +
                "xxx.\n" +
                "xx.top\n" +
                " https://zcy-gov-open-doc.oss-cn-north-2-gov-1.aliyuncs.com/1084PT/330781/10006732554/20209/c63f1135-ee1d-4adc-a08a-ef4c5eebd326\n" +
                "https://zjjcmspublic-test.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn//jsearchfront/template/jcse/0/1569/images/logo_03.png\n" +
                "<p>https://zjjcmspublic-test.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn//jsearchfront/template/jcse/0/1569/images/logo_03.png</p>\n" +
                "<p>https://zjjcmspublic-test.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn//jsearchfront/template/jcse/0/1569/images/logo_03.png</p>\n" +
                "https://zjjcmspublic-test.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn?@@@@@\n" +
                "https://zjjcmspublic-test.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn\n" +
                "张三.baidu.com\n" +
                "sdasd.gifddddd\n" +
                "http://www.baidu.com";

        String re = "[a-zA-z0-9.-]*\\.(net|com|cn|org|int|vip|club|hk|ink|biz|coop|xyz|cc|at|ad|ae|af|ai|al|am|ao|aq|ar|as|au|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bw|bz|ca|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cy|cz|$e|$j|$k|$m|$o|$z|ec|ee|eg|eh|er|es|et|fi|fj|fk|fm|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gp|gq|gr|gt|gu|gw|gy|hk|hn|hr|ht|hu|id|ie|il|in|iq|ir|is|it|jm|jo|jp|ke|kh|km|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|ml|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pr|pt|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|td|tg|th|tj|tk|tm|to|tp|tt|tw|tz|ua|ug|uk|us|uy|uz|va|ve|vg|vi|vn|wf|ws|ye|yu|za|zm|zr|zw)[^a-z0-9A-Z]";

        Pattern pattern = Pattern.compile(re);
        Matcher matcher = pattern.matcher(text);
        while (matcher.find()) {
            String group = matcher.group();
            System.out.println(group);
        }
    }
}
